package au.com.bus4u.service.impl;

import au.com.bus4u.dao.DaoSupport;
import au.com.bus4u.service.AuctionService;
import au.com.bus4u.service.ShuttleBusOrderService;
import au.com.bus4u.utils.PageData;
import lombok.extern.java.Log;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("shuttleBusOrderService")
@Log
public class ShuttleBusOrderImpl implements ShuttleBusOrderService {

    @Autowired
    private DaoSupport daoSupport;
    @Autowired
    private AuctionService auctionService;
    private String mapper = "ShuttleBusOrderMapper.";

    /**
     * 新增 班车订单
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int save(PageData pd) throws Exception {
        PageData currentUser = getCurrentUser();
        //新增订单填入默认值
        pd.put("order_prefix_name","bus4u#"+pd.get("shuttle_name"));
        pd.put("order_status",0);
        pd.put("order_status_name","Waiting");
        pd.put("contact_name",currentUser.get("avatar"));
        return (int) daoSupport.save(mapper+"save", pd);
    }

    /**
     * 查询 所以班车订单
     * @param pd
     * @return
     * @throws Exception
     */
    public List<PageData> list(PageData pd) throws Exception{

        List<PageData> list = (List<PageData>) daoSupport.findForList(mapper+"list",pd);
        return list;
    }





    /**
     * 获取当前登录用户数据
     * @return
     */
    private PageData getCurrentUser() {
        return (PageData) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
    }
    private String getCurrentUserID(){
        PageData pd = (PageData) SecurityUtils.getSubject().getSession().getAttribute("currentUser");
        String user_id = pd.get("user_id").toString();
        return user_id;
    }
}
